package lab02.test24;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test24 {
    public static void main(String[] args) throws ParseException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入第一个日期，格式如20171030:");
        String day1 = scanner.nextLine();

        String year = day1.substring(0,4);
        String month = day1.substring(4,6);
        String day = day1.substring(6);
        Calendar calendar = Calendar.getInstance();

        calendar.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
        Date date1 = calendar.getTime();
        System.out.println("请输入第二个日期，格式如20100310:");
        day1 = scanner.nextLine();
        year = day1.substring(0,4);
        month = day1.substring(4,6);
        day = day1.substring(6);
        calendar.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
        Date date2 = calendar.getTime();

        long differ = (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000);
        if (differ < 0) {
            differ = (date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000);
        }
        System.out.println("两个日期之间相差" + differ + "天");
    }
}
